# frozen_string_literal: true

class CreateRuleEntities < ActiveRecord::Migration[6.0]
  def change
    create_table :rule_entities do |t|
      t.integer :rule_id, null: false,  limit: 8
      t.string  :type,    null: false,  limit: 64
      t.string  :status,  null: false,  limit: 32
      t.string  :stage,   null: false,  limit: 32
      t.string  :policy,  null: false,  limit: 32
      t.integer :version, null: false,  limit: 4, default: 0
      t.timestamps        null: false
    end

    add_index :rule_entities, %i[version rule_id], unique: true
    add_foreign_key :rule_entities, :rules
  end
end
